<?php
include_once("config.php");
if (isset($_SESSION['adminName'])){
	$isAdmin=true;
}else{
	$isAdmin=false;
}
if ($isAdmin){
	if (isset($_POST['restuarantname']) && isset($_POST['restuarantaddress']) && isset($_POST['restuarantaverageconsumption']) && isset($_POST['restuarantcuisines']) && isset($_POST['restuarantcontactnumber']) && isset($_POST['restuarantdescription'])){
	$isInputValid=true;
	$restuarantname=mysql_real_escape_string(stripcslashes($_POST['restuarantname']));
	$restuarantaddress=mysql_real_escape_string(stripcslashes($_POST['restuarantaddress']));
	$restuarantaverageconsumption=intval(mysql_real_escape_string(stripcslashes($_POST['restuarantaverageconsumption'])));
	$restuarantcuisines=mysql_real_escape_string(stripcslashes($_POST['restuarantcuisines']));
	$restuarantcontactnumber=mysql_real_escape_string(stripcslashes($_POST['restuarantcontactnumber']));
	$restuarantdescription=mysql_real_escape_string(stripcslashes($_POST['restuarantdescription']));
	}else{
		$isInputValid=false;
	}
}else{
	header("location: adminIndex.php");
}
if ($isInputValid){
	$query="SELECT * FROM restaurant WHERE address='$restuarantaddress'";
  $result1=mysql_query($query);
  $row=mysql_num_rows($result1);
  if ($row==1){
  	$canUpdate=true;
  }
  else{
  	$canUpdate=false;
  }
}else{
	echo "no such restuarant!";
	$canUpdate=false;
}
if ($canUpdate){
	$queryStr="UPDATE restaurant SET name='$restuarantname', argC='$restuarantaverageconsumption', cuisines='$restuarantcuisines', contactNum='$restuarantcontactnumber', description='$restuarantdescription' WHERE address='$restuarantaddress'";
	mysql_query($queryStr) or die("Cannot update restuarant: ".mysql_error());
	header("location: viewrestuarant.php");
}else{
	" the restuarant cannot be updated";
}
?>
